﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Views.Base;
using DTO;
using BLL;
using DAL;

namespace CRM.GUI.QLHeThong
{
    public partial class ucSample : UserControl
    {
       
        private SampleFunc Func = new SampleFunc();

        private SampleEntity  _sample = new SampleEntity ();

        public ucSample()
        {

            InitializeComponent();
            
           gridViewSample.DataSource = Func .LoadListSample ();
           colSampleCode .FieldName = "Sample_Code" ;
           colSampleName .FieldName = "SampleName";
           colDescription .FieldName = "Description";
           

        }

               // private void grdViewCollector_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)

        private void gridView1_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {

            _sample = (SampleEntity  ) gridView1.GetRow(e.RowHandle);
            txtCode_Up.Text  = _sample.Sample_Code;
            txtName_Up.Text  = _sample.SampleName;
            txtDct_Up.Text = _sample.Description;
        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            _sample.Sample_Code = txtCode_Up.Text;
            _sample.SampleName = txtName_Up.Text;
            _sample.Description = txtDct_Up.Text;
            Func.UpdateSample(_sample);
            
            //refesh 
            gridViewSample.DataSource = Func.LoadListSample();
            txtCode_Up.Text = "";
            txtDct_Up.Text = "";
            txtName_Up.Text = "";
             
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            _sample.Sample_Code = txtCode.Text;
            _sample.SampleName = txtName.Text;
            _sample.Description = txtDct.Text;
           // Func.AddSample(_sample.Sample_Code, _sample.SampleName, 0, _sample .Description  , 0);
            Func.AddSample(_sample.Sample_Code, _sample.SampleName, 0, _sample.Description, 0);
            //refesh
            gridViewSample.DataSource = Func.LoadListSample();
            txtCode.Text = "";
            txtName.Text = "";
            txtDct.Text = "";


        }

     
      
    }
}
